package com.muyan.singleton.v2;

/**
 * @Author: YLTDMenglc
 * @Date: 2019/6/11
 * @Time: 13:36
 * @Description:懒汉模式变种 2, 使用了synchronized关键字，既可以延迟加载，又线程安全，但是执行效率低。
 */
public class Sinleton2 {

    private static Sinleton2 sinleton;

    private Sinleton2() {

    }

    public synchronized static Sinleton2 getSinleton() {
        try {
            Thread.sleep(100);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (sinleton == null) {
            sinleton = new Sinleton2();
        }
        return sinleton;
    }
}
